'use strict';

const { Controller } = require('egg');

class ChatController extends Controller {

  /**
   * ws on receive message
   */
  async index() {
    const message = this.ctx.args[0];
    console.log('chat :', message + ' : ' + process.pid);
    const say = await this.ctx.service.user.say();
    this.ctx.socket.emit('res', say);
  }
  /**
   *  when this ws connection open
   */
  async connected() {
    console.log('connected');
  }

  /**
   *  when the ws connection disconnect
   */
  async disconnect() {
    const message = this.ctx.args[0];
    console.log(message);
  }
}

module.exports = ChatController;
